package com.ht.controller;

import com.ht.data.Result;
import com.ht.domain.bo.TbDepartmentBO;
import com.ht.domain.vo.TbDepartmentVO;
import com.ht.em.ResultEnum;
import com.ht.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 科室表
 */
@RestController
@RequestMapping("department")
@Api
@RefreshScope //开启自动刷新配置
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 查询所有科室
     * @return
     */
    @ApiOperation("查询所有科室")
    @PostMapping("findDepartmentAll")
    public Result findDepartmentAll(){
        List<TbDepartmentBO> departmentBOList = departmentService.findDepartmentAll();
        //判断是否查询到数据,如果没有数据返回状态码(未找到符合条件的数据)
        if (departmentBOList.size() <= 0){
            return Result.response(ResultEnum.QUERY_NULL);
        }
        //将bo类转成vo类返回数据到前台
        List<TbDepartmentVO> departmentVOList = new ArrayList<>();
        departmentBOList.forEach((departmentBO) -> {
            TbDepartmentVO departmentVO = new TbDepartmentVO(departmentBO);
            departmentVOList.add(departmentVO);
        });
        return Result.OK().setData(departmentVOList);
    }
}
